<?php

class Admin_Controllers_Index extends Libs_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->view->render('index/index');
    }

    public function checkLogin() {
        $e = $_POST['txtEmail'];
        if (isset($_COOKIE['ad_pass']) && strlen($_POST['txtPass']) > 16) {
            $p = $_COOKIE['ad_pass'];
        } else {
            $p = Hash::create($_POST['txtPass']);
        }
        $check = new Admin_Models_User();
        $user = $check->checkUserLogin($e, $p);
        if (!empty($user)) {
            $_SESSION['user_email'] = $user['email'];

            if (isset($_POST['chkRemember'])) {
                setcookie('email', $e, time() + 3600, '/');
                setcookie('ad_pass', $p, time() + 3600, '/');
            }
        }

        $url = URL_BASE . '/admin';
        header("location: $url");
    }

}
